package com.example.maybeaccount.Spinner;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.maybeaccount.R;

import java.util.List;

public class NormalAdapter<T> extends BaseAdapter {
    protected Context context;
    private List<T> datas;
    protected LayoutInflater inflater;
    protected int layoutId;

    public NormalAdapter(Context context, List<T> datas, int layoutId) {
        this.context = context;
        this.datas = datas;
        inflater = LayoutInflater.from(context);//关联布局
        this.layoutId = layoutId;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView == null){
            viewHolder = new ViewHolder();
            convertView = inflater.inflate(R.layout.spinner_popup_item,null);
            viewHolder.textTv = (TextView) convertView.findViewById(R.id.tv_item);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.textTv.setText(getItem(position).toString());
        return convertView;
    }

    private class ViewHolder{
        private TextView textTv;
    }

}